import { ShareClientEnum, ShareModelEnum, ShareEnum } from '@/core/enum';
import { UserToken } from '@/core/consts';
import { queryShare } from '@/core/api';
import { handleShowToast } from '@/core/utils';
import { useShopConfigStore } from '@/core/store';

interface RequestParam {
	client : ShareClientEnum,
	url : string,
	type : ShareModelEnum,
	page : ShareEnum,
	params ?: any,
	token ?: string
}

const getDefaultShareData = () => {
	const shopConfigStore = useShopConfigStore();
	return {
		title: shopConfigStore.config?.shopName,
		imageUrl: shopConfigStore.config?.shopLogo,
		path: "/pages/home/home"
	}
}

const getShareUrl = async (requestParam : RequestParam) => {
	let data : RequestParam = requestParam;
	if (uni.getStorageSync(UserToken)) {
		data['token'] = uni.getStorageSync(UserToken)
	}
	const share = await queryShare(data);
	if (share.status) {
		return share.data;
	} else {
		handleShowToast(share.msg);
	}
}

export {
	getShareUrl,
	getDefaultShareData,
}